package best.driver.android.Map;

import java.io.Serializable;

public class Address implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 6174157281422967313L;

    private static final String NULL_NAME = "当前位置";

    private static final String NULL_ADDRESSDETAIL = "使用地图中定位的地点";

    private String name;

    private String city;

    private String cityId;

    private String addressDetail;

    private int ePointType;

    private double lat;

    private double lng;

    private long lastUseTime;

    /**
     * 去掉 公交线路和地铁线路
     * poi类型，0：普通点，1：公交站，2：公交线路，3：地铁站，4：地铁线路,
     * */
    public static boolean isInvalid(int eType) {
        switch (eType) {
            case 2:
            case 4:
                return true;
        }
        return false;
    }

    public String getAddressDetail() {
        return addressDetail;
    }

    public void setAddressDetail(String addressDetail) {
        this.addressDetail = addressDetail;
    }

    public double getLat() {
        return lat;
    }

    public void setLat(double lat) {
        this.lat = lat;
    }

    public double getLng() {
        return lng;
    }

    public void setLng(double lng) {
        this.lng = lng;
    }

    public String getName() {
        return name==null?"":name;
    }

    public void setName(String tittle) {
        this.name = tittle;
    }

    public LatLng getPoint() {
        return new LatLng(lat, lng);
    }

    public void setPoint(LatLng point) {
        if (point == null) {
            return;
        }
        this.lat = point.latitude;
        this.lng = point.longitude;
    }

    public String getCity() {
        if (city != null) {
            return city;
        }
        return "";
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCityId() {
        return cityId;
    }

    public void setCityId(String cityId) {
        this.cityId = cityId;
    }

    public long getLastUseTime() {
        return lastUseTime;
    }

    public void setLastUseTime(long lastUseTime) {
        this.lastUseTime = lastUseTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null)
            return false;
        if (!(o instanceof Address))
            return false;
        final Address address = (Address) o;
        if (address.getLat() == getLat() && address.getLng() == getLng())
            return true;
        return false;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(String.format("%s=\"%s\"&", "name", name));
        sb.append(String.format("%s=\"%s\"&", "city", city));
        sb.append(String.format("%s=\"%s\"&", "cityId", cityId));
        sb.append(String.format("%s=\"%s\"&", "addressDetail", addressDetail));
        sb.append(String.format("%s=\"%s\"&", "ePointType", ePointType));
        sb.append(String.format("%s=\"%s\"&", "LatLng", getPoint()));
        return sb.toString();
    }

    public static Address createNullAddress(){
        Address address = new Address();
        address.setName(NULL_NAME);
        address.setAddressDetail(NULL_ADDRESSDETAIL);
        return address;
    }

    public boolean isNullAddress(){
        return NULL_NAME.equals(name) && NULL_ADDRESSDETAIL.equals(addressDetail);
    }
}
